package com.lovegu.server.controller;

import com.alibaba.cola.dto.SingleResponse;
import com.lovegu.server.client.dto.UserDTO;
import com.lovegu.server.client.vo.UserVO;
import com.lovegu.server.infrastructure.modules.user.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;

/**
 * 用户管理
 *
 * @author 老顾 1437594522@qq.com
 * @since  2022/11/19 14:42
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/server/user")
public class UserController {

    private final UserService userService;

    @PostMapping("/addUser")
    public SingleResponse addUser(@RequestBody UserDTO userDTO){
        userService.addUser(userDTO);
        return SingleResponse.buildSuccess();
    }

    @PostMapping("/deleteUser")
    public SingleResponse deleteUser(@RequestBody UserDTO userDTO) {
        userService.deleteUser(userDTO);
        return SingleResponse.buildSuccess();
    }

    @PostMapping("/deleteBatchUser")
    public SingleResponse deleteBatchUser(@RequestBody Collection<Integer> userDTOList) {
        userService.deleteBatchUser(userDTOList);
        return SingleResponse.buildSuccess();
    }

    @PostMapping("/updateUser")
    public SingleResponse updateUser(@RequestBody UserDTO userDTO) {
        userService.updateUser(userDTO);
        return SingleResponse.buildSuccess();
    }

    @PostMapping("/selectUser")
    public SingleResponse<UserVO> selectUser(@RequestBody UserDTO userDTO) {
        UserVO userVO = userService.selectUser(userDTO);
        return SingleResponse.of(userVO);
    }

    @PostMapping("/selectBatchUser")
    public SingleResponse<List<UserVO>> selectBatchUser(@RequestBody UserDTO userDTO) {
        List<UserVO> userVOList = userService.selectBatchUser(userDTO);
        return SingleResponse.of(userVOList);
    }

    @PostMapping("/loginUser")
    public SingleResponse loginUser(@RequestBody UserDTO userDTO){
        UserVO userVO = userService.loginUser(userDTO);
        return SingleResponse.of(userVO);
    }
}
